using System;
using NUnit.Framework;
using DotNetXmlSwfChart;

namespace DotNetXmlSwfChart.UnitTest
{
    [TestFixture]
    public class DrawImageFixture
    {
        [Test]
        public void DrawImageBackgroundLayerDissolveTransition()
        {
            ImageTest(DrawLayer.background, TransitionType.dissolve);
        }

        [Test]
        public void DrawImageForegroundLayerDissolveTransition()
        {
            ImageTest(DrawLayer.foreground, TransitionType.dissolve);
        }

        [Test]
        public void DrawImageBackgroundLayerDropTransition()
        {
            ImageTest(DrawLayer.background, TransitionType.drop);
        }

        [Test]
        public void DrawImageForegroundLayerDropTransition()
        {
            ImageTest(DrawLayer.foreground, TransitionType.drop);
        }

        [Test]
        public void DrawImageBackgroundLayerSpinTransition()
        {
            ImageTest(DrawLayer.background, TransitionType.spin);
        }

        [Test]
        public void DrawImageForegroundLayerSpinTransition()
        {
            ImageTest(DrawLayer.foreground, TransitionType.spin);
        }

        [Test]
        public void DrawImageBackgroundLayerScaleTransition()
        {
            ImageTest(DrawLayer.background, TransitionType.scale);
        }

        [Test]
        public void DrawImageForegroundLayerScaleTransition()
        {
            ImageTest(DrawLayer.foreground, TransitionType.scale);
        }

        [Test]
        public void DrawImageBackgroundLayerZoomTransition()
        {
            ImageTest(DrawLayer.background, TransitionType.zoom);
        }

        [Test]
        public void DrawImageForegroundLayerZoomTransition()
        {
            ImageTest(DrawLayer.foreground, TransitionType.zoom);
        }

        [Test]
        public void DrawImageBackgroundLayerBlinkTransition()
        {
            ImageTest(DrawLayer.background, TransitionType.blink);
        }

        [Test]
        public void DrawImageForegroundLayerBlinkTransition()
        {
            ImageTest(DrawLayer.foreground, TransitionType.blink);
        }

        [Test]
        public void DrawImageBackgroundLayerSlideRightTransition()
        {
            ImageTest(DrawLayer.background, TransitionType.slide_right);
        }

        [Test]
        public void DrawImageForegroundLayerSlideRightTransition()
        {
            ImageTest(DrawLayer.foreground, TransitionType.slide_right);
        }

        [Test]
        public void DrawImageBackgroundLayerSlideLeftTransition()
        {
            ImageTest(DrawLayer.background, TransitionType.slide_left);
        }

        [Test]
        public void DrawImageForegroundLayerSlideLeftTransition()
        {
            ImageTest(DrawLayer.foreground, TransitionType.slide_left);
        }

        [Test]
        public void DrawImageBackgroundLayerSlideUpTransition()
        {
            ImageTest(DrawLayer.background, TransitionType.slide_up);
        }

        [Test]
        public void DrawImageForegroundLayerSlideUpTransition()
        {
            ImageTest(DrawLayer.foreground, TransitionType.slide_up);
        }

        [Test]
        public void DrawImageBackgroundLayerSlideDownTransition()
        {
            ImageTest(DrawLayer.background, TransitionType.slide_down);
        }

        [Test]
        public void DrawImageForegroundLayerSlideDownTransition()
        {
            ImageTest(DrawLayer.foreground, TransitionType.slide_down);
        }

        [Test]
        public void DrawImageBackgroundLayerNoTransition()
        {
            ImageTest(DrawLayer.background, TransitionType.none);
        }

        [Test]
        public void DrawImageForegroundLayerNoTransition()
        {
            ImageTest(DrawLayer.foreground, TransitionType.none);
        }

        private void ImageTest(DrawLayer layer, TransitionType type)
        {
            string testXml =
                "<image layer='{0}' " +
                       "transition='{1}' " +
                       "delay='1.2' " +
                       "duration='2.2' " +
                       "url='images/testimage.jpg' " +
                       "x='20' " + 
                       "y='40' " + 
                       "width='200' " +  
                       "height='100' " + 
                       "rotation='1' " + 
                       "alpha='1' " +
                       "/>";
            DrawImage image = new DrawImage();
            image.Layer = layer;
            image.Transition = type;
            image.Delay = 1.2;
            image.Duration = 2.2;
            image.Url = "images/testimage.jpg";
            image.X = 20;
            image.Y = 40;
            image.Width = 200;
            image.Height = 100;
            image.Rotation = 1;
            image.Alpha = 1;
            Assert.AreEqual(
                string.Format(testXml, layer.ToString(), type.ToString()),
                image.ToSourceXML());
        }
    }
}
